home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / tex-k / tex-k-archive.past / tex-k-archive.gz / tex-k-archive / 000174_Dale_Moore@MOO….FAC.CS.CMU.EDU_Mon Jan 24 05:58:23 1994.msg < prev    next >
Internet Message Format  |  1994-10-11  |  3KB

  1. Received: from MOORE.FAC.CS.CMU.EDU by cs.umb.edu with SMTP id AA24614
  2.   (5.65c/IDA-1.4.4 for <tex-k@CS.UMB.EDU>); Mon, 24 Jan 1994 18:18:32 -0500
  3. Received: from MOORE.FAC.CS.CMU.EDU by MOORE.FAC.CS.CMU.EDU id aa04185;
  4.           24 Jan 94 10:58:44 EST
  5. To: tex-k@CS.UMB.EDU
  6. Cc: Dale.Moore@cs.cmu.edu
  7. Subject: xputenv.c bugs
  8. Date: Mon, 24 Jan 94 10:58:23 EST
  9. Message-Id: <4183.759427103@MOORE.FAC.CS.CMU.EDU>
  10. From: Dale_Moore@MOORE.FAC.CS.CMU.EDU
  11.  
  12.  
  13. Short Version:
  14.  
  15. I found bugs in
  16.  
  17.     dvipsk-5.521a/kpathsea/xputenv.c
  18.     xdvik-1.4/kpathsea/xputenv.c
  19.  
  20. Please let me know where to forward the bug report.
  21.  
  22.  
  23. Long Version:
  24.  
  25. In the routine xputenv, there are a couple things that didn't
  26. work for me.
  27.  
  28. In that routine, you do the following...
  29.  
  30.       unsigned i;
  31.       unsigned len = strlen (var_name);
  32.       for (i = 0; i < saved_len && !old_item; i++)
  33.         {
  34.           if (strncmp (saved_env_items[i], var_name, len) == 0)
  35.             {
  36.               old_item = getenv (var_name);
  37.               assert (old_item);
  38.               old_item -= (len + 1);  /* Back up to the `NAME='.  */
  39.             }
  40.         }
  41.  
  42.     ...
  43.  
  44.       if (old_item)
  45.         free(old_item);
  46.  
  47. Now, assume that we've already stored an environment variable,
  48. called "FOOBAR".  It has some reasonable value.  After
  49. we store that variable, we want to store some other value associated
  50. with a new envionrment variable named "FOO".  In that code fragment
  51. above, it will find "FOO" in the string "FOOBAR", and proceed to
  52. getenv the value of "FOO" and try to free it.
  53.  
  54. Another thing that I don't like, is that you free the results
  55. from getenv.  From the C standard ANSI X3.159-1989
  56.  
  57.     The getenv function searches an evnironment list, provided
  58.     by the host environment, for a string that matches the string
  59.     pointed to by name.  The set of environment names and the
  60.     method for altering the environment list are implementation-
  61.     defined.
  62.  
  63.     ....
  64.  
  65.     The getenv function returns a pointer to a string associated
  66.     with the matched list member.  The string pointed to shall not
  67.     be modified by the program, but may be overwritten by a
  68.     subsequent call to the getenv function.
  69.  
  70. And from POSIX 1003.1-1988 (A little out of date I know)
  71.  
  72.     The returned value from getenv() may point to static data
  73.     and therefore may be overwritten by each call.
  74.  
  75. It appears that your code makes some assumptions about the implementation
  76. of getenv and putenv.  Those assumptions didn't hold in my local environment,
  77. and I had to change the implementation of that routine to make things
  78. behave as expected.  My changed implementation of xputenv now looks like
  79.  
  80.   void
  81.   xputenv P2C(const_string, var_name,  const_string, value)
  82.   {
  83.     string new_item = concat3 (var_name, "=", value);
  84.   
  85.     if (putenv (new_item) < 0)
  86.       FATAL1("putenv(\"%s\") failed", new_item);
  87.   }
  88.  
  89. It may leak some memory, but it works.  Too bad they didn't ANSI-ify or
  90. POSIX-ify putenv().  Then we'd have something to go on.
  91.  
  92. Perhaps a compromise would be to #ifdef various sections based on the
  93. implementation of getenv and putenv.
  94.  
  95. In our local implementation of putenv, the routine is somewhat smart enough
  96. to malloc and realloc and free memory as needed.
  97.  
  98. If you have comments or questions about this, please feel free to send
  99. mail to me, Dale.Moore@cs.cmu.edu .
  100.  
  101.  
  102. ------- End of Forwarded Message
  103.